using System;
using System.Data;
using System.Data.SqlClient;

namespace YY.Basic.DB
{
	
	public class ReaderRelateObj
	{
		protected DBCommon				m_db;	
		protected SqlCommand			m_dSelCommand;
		protected SqlDataReader			m_Reader;
		protected CommandBehavior		m_Behavior;


        public ReaderRelateObj(DBCommon db,string sCommand)
		{
            m_db = db;
			m_dSelCommand=new SqlCommand(sCommand,m_db.Connection);
			m_Behavior=CommandBehavior.Default;

		}

		public ReaderRelateObj(DBCommon db,string sCommand,CommandBehavior behavior)
		{
            m_db = db;
			m_dSelCommand=new SqlCommand(sCommand,m_db.Connection);
			m_Behavior=behavior;
		}

		public virtual void OpenReader()
		{
			if(m_Reader==null)
			{
				this.m_db.ConnOpen();
				m_Reader=m_dSelCommand.ExecuteReader(this.m_Behavior);
			}
		}
		
		public SqlDataReader Reader
		{
			get
			{
				if(this.m_Reader==null)
				{
					this.OpenReader();
				}

				return this.m_Reader;
			}
		}

		public void CloseConn()
		{
			this.m_db.ConnClose();
			this.m_Reader=null;
		}


	}
}
